package com.zzptc.gyc.myappkotlin

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.POST

class MainActivity : AppCompatActivity() {
    interface SearchSerVice {
        @FormUrlEncoded
        @POST("Interface/UserLine/search")
        fun getAllsearch(@Field("pos")pos:Int): Call<SearchData>
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val retrofit = Retrofit.Builder()
            .baseUrl("http://hh1.me:5001/")
            .addConverterFactory(GsonConverterFactory.create())
            .build()
        val searchSerVice = retrofit.create(SearchSerVice::class.java)
        val call = searchSerVice.getAllsearch(1)
        call.enqueue(object :Callback<SearchData>{
            override fun onFailure(call: Call<SearchData>, t: Throwable) {

            }

            override fun onResponse(call: Call<SearchData>, response: Response<SearchData>) {
                tv_id.text=response.body()?.message

            }
        })
    }
    public fun f1():Unit{//第一种完整语法
    }
    fun f2(){//这样省略可以减少代码量
    }
}
